package com.alks.function.service.async;

import com.alks.common.utils.excelUtils.nestExcel.NestExcelUtil;
import com.alks.common.utils.export.service.FileExportTask;
import com.alks.common.utils.export.dto.MockMultipartFile;
import com.alks.function.data.vo.stock.ReportStockInVO;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @author: chen
 * @date: 2024/12/27
 * @description:
 */
@Slf4j
public class TestFileExport extends FileExportTask {

    private List<ReportStockInVO> dataList;
    private List<List<String>> heads;

    public TestFileExport(List<ReportStockInVO> dataList, List<List<String>> heads) {
        super();
        this.dataList = dataList;
        this.heads = heads;
    }

    @Override
    public MockMultipartFile generateFile(String fileName) {
        log.debug("开始生成导出文件 {}", fileName);
        String name = fileName.split("\\.")[0];
        MockMultipartFile file = new NestExcelUtil<ReportStockInVO>().exportDataAndUpload(dataList, heads, name);
        if (file != null) {
            callback.onFileGenerated(file);
            log.debug("文件生成成功");
        } else {
            log.warn("文件生成失败");
        }
        return file;
    }
}
